#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define str string
#define all(x) (x).begin(),(x).end()
#define ms(a,t) memset(a,t,sizeof(a))
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MP make_pair
#define pb push_back
#define fi first
#define se second
#define db double
const int maxn = 5e6+10;
const int mod = 1e9+7;
const ll INF = 0x3f3f3f3f;
const db eps = 1e-7;
ll lim;
ll f[maxn];
void add(int x) {
	for(int i = x; i <= lim; i++) {
		f[i] = (f[i] + f[i-x]) % mod;
	}
}
void Solve() {
	ll x,y;
	cin >> x >> y; 
	ll ans = 0;
	for(int i = 0; (x<<i) <= y; i++) {
		lim = y-(x<<i); ms(f,0); f[0] = 1;
		for(int j = 0; j <= i; j++) {
			add(1<<j);
		}
		ans += f[lim];
//		cout<<f[lim]<<'\n';
	}
	cout<<ans%mod<<'\n';
}
int main() {
	freopen("op.in","r",stdin);
	freopen("op.out","w",stdout);
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//	int T; cin >> T; while(T--)
	Solve();
	return 0;
}
